package com.gxa.ehome.service.impl;

import com.gxa.ehome.mapper.SysUserMapper;
import com.gxa.ehome.pojo.SysUser;
import com.gxa.ehome.service.SysUserService;
import com.gxa.ehome.util.MD5Creater;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {

    @Resource
    SysUserMapper sysUserMapper = null;

    @Override
    public boolean login(String jobNumber,String password) {
        System.out.println("SysUserServiceImpl login ");
        return false;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.READ_COMMITTED ,
            rollbackFor ={Throwable.class}
            )
    public void deleteById(Integer id) {

        sysUserMapper.deleteById(id);
    }

    @Override
    public void register(SysUser sysUser) {
        sysUserMapper.save(sysUser);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.SUPPORTS,readOnly = true)
    public SysUser selectById(Integer id) {
        SysUser byId = sysUserMapper.findById(id);
        return byId;
    }

    @Override
    public List<SysUser> selectAll() {
        return sysUserMapper.findAll(null);
    }

    @Override
    public void update(SysUser sysUser) {
        sysUserMapper.update(sysUser);
    }

    /*@Override
    public void test() {
        // 同时调用register和deleteById方法, 观察事务是否在管理
        // 删除方法
        deleteById(8);
        // 注册方法
        SysUser sysUser = new SysUser();
        sysUser.setJobNumber("aaa");
        sysUser.setName("aaa");
        sysUser.setPassword(MD5Creater.encode("123456"+sysUser.getPassword()));
        register(sysUser);
    }*/



}
